1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int mod=99999999; struct matrix { ll a[8][8]; }; matrix multiply(matrix x,matrix y,int m,int n,int s) { matrix tmp; memset(tmp.a,0,sizeof(tmp.a)); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ for(int k=0;k<s;k++){ tmp.a[i][j]=(tmp.a[i][j] + (x.a[i][k] * y.a[k][j])%mod)%mod; } } } return tmp; } matrix tmp={ 0,1,1,0,0,0,0,0, 1,0,0,1,0,0,0,0, 0,0,0,0,1,0,0,0, 0,0,0,0,0,1,0,0, 2,3,0,0,0,0,0,0, 0,2,0,0,0,0,0,0, 1,0,0,0,0,0,1,0, 0,1,0,0,0,0,0,1 }; int main() { matrix res; ll f[8]={6,5,1,4,2,3,5,3}; ll sum1,sum2,n; memset(res.a,0,sizeof(res.a)); for(int i=0;i<8;i++){ res.a[i][i]=1; } cin>>n; if(n==1) cout<<"2"<<endl<<"3"<<endl; if(n==2) cout<<"1"<<endl<<"4"<<endl; if(n==3) cout<<"6"<<endl<<"5"<<endl; if(n>=4){ n-=3; while(n) { if(n&1) res=multiply(res,tmp,8,8,8);
n>>=1; tmp=multiply(tmp,tmp,8,8,8); } sum1=0; sum2=0; for(int i=0;i<8;i++) { sum1=(sum1+(f[i]*res.a[i][0])%mod)%mod; sum2=(sum2+(f[i]*res.a[i][1])%mod)%mod; } cout<<sum1<<endl; cout<<sum2<<endl; } return 0; }
|